<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('流程审批')" />
    <th:block th:include="include :: datetimepicker-css" />
    <style type="text/css">
        table label.error{position: inherit;}select + label.error{z-index:1;right:40px;}
    </style>
</head>
<body class="white-bg">
<div class="col-sm-8">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-sjcontract-add" th:object="${obj}">
    	<h4 class="form-header h4">基本信息</h4>
            <input name="id" th:field="*{id}" type="hidden" />
            <input name="gcProjectid" type="hidden" th:field="*{gcProjectid}" />
            <input type="hidden" id="approvename" name="approvename" th:value="${approvename}" />
            <input type="hidden" name="owner" th:field="*{owner}" />
        	<input type="hidden" name="ownerId" th:field="*{ownerId}" />
        	<div class="form-group">    
                <label class="col-sm-1 control-label">出差事由：</label>
                <div class="col-sm-2">
                    <input name="chucsy" th:field="*{chucsy}" class="form-control" type="text" readonly="readonly" autoComplete="off">
                </div>
                <label class="col-sm-1 control-label">核销时间：</label>
                <div class="col-sm-2">
                    <div class="input-group date">
                        <input name="chucsj" th:value="${#dates.format(obj.chucsj, 'yyyy-MM-dd')}" readonly="readonly" class="form-control" placeholder="yyyy-MM-dd" type="text" autoComplete="off">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            	<label class="col-sm-1 control-label">报销人：</label>
                <div class="col-sm-2">
                    <input name="chucr" th:field="*{chucr}" class="form-control" type="text" readonly="readonly" autoComplete="off">
                </div>
                <label class="col-sm-1 control-label is-required">费用类型：</label>
                <div class="col-sm-2">
                	<select name="type" th:field="*{type}" class="form-control" readonly="readonly" th:with="type=${@dict.getType('fyhx_type')}" required>
					  <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictLabel}">
					  </option>
					</select>
                </div>
<!--             	<label class="col-sm-1 control-label is-required">单据数量：</label> -->
<!--                 <div class="col-sm-1"> -->
<!--                     <input name="djsl" th:field="*{djsl}" class="form-control" type="text" autoComplete="off" required> -->
<!--                 </div> -->
            </div>
            <div class="form-group"> 
            	<label class="col-sm-1 control-label is-required">申请部门：</label>
                <div class="col-sm-2">
                    <input name="dept" class="form-control" type="text" th:field="*{dept}" autoComplete="off" readonly="readonly" required>
                    <input name="deptId" th:field="*{deptId}" type="hidden">
                </div>
                <label class="col-sm-1 control-label is-required">项目所属：</label>
                <div class="col-sm-2">
                    <select name="authority" th:field="*{authority}" class="form-control" readonly="readonly" required>
						<option th:each="cl:${deptlis}" th:value="${cl.deptId}" th:text="${cl.deptName}"></option>
					</select>
                </div>
                <label class="col-sm-1 control-label is-required">付款单位：</label>
            	<div class="col-sm-2">
            		<select name="ztdw" th:field="*{ztdw}" class="form-control" th:with="type=${@dict.getType('sj_gongs')}" readonly="readonly" required>
                    	<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                	</select>
                </div>
            </div>
            </div>
            <h4 class="form-header h4" style="margin-top: 8px;margin-bottom: 0px;">表单项</h4>
            <div class="row" >
                <div class="col-sm-12">
				    <table id="bootstrap-table"></table>
                </div>
            </div>
        <h4 class="form-header h4" style="margin-top: 18px;">审核信息</h4>
        <div class="form-group">
            <label class="col-sm-2 control-label ">审批结果：</label>
            <div class="col-sm-4">
                <label class="radio-box">
                    <input type="radio" checked="" value="true" name="level4approve">同意</label>
                <label class="radio-box">
                    <input type="radio" value="false" name="level4approve">拒绝</label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">审批意见：</label>
            <div class="col-sm-10">
                <textarea rows="5" name="fwshyj" class="form-control" required></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-3 col-sm-offset-3">
                <input type="hidden"  name="taskid" id="taskid" th:value="${taskid}">
                <input type="hidden"  name="status" id="status" th:value="1">
                <input type="hidden"  name="id" id="id" th:value="${obj.id}">
                <button class="btn btn-primary" onclick="submitHandler()" type="button"><i class="fa fa-check"></i>&nbsp;提交</button>
            </div>
        </div>
    </form>
</div>
</div>
<div id="ibox-content" class="col-sm-4">
    <div id="vertical-timeline" class="vertical-container dark-timeline">
    </div>
</div>
</body>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:src="@{/js/jquery.tmpl.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "task/manage"
    $("#form-sjcontract-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
    	if ($.validate.form()) {
        var taskid = $("#taskid").val();
        var check = document.querySelector("input[name='level4approve']:checked").value;
        if(check=="false"){
        	$("#status").val(4);
        }else{
        	$("#status").val(2);
        }
        var comment = $("textarea[name=fwshyj]").val();
        
        $.operate.save("edit4check", $('#form-sjcontract-add').serialize(), function(){
        	var json = {"level4approve": check, "level5": $("#approvename").val(), "comment": comment};
	        $.ajax({
	            url : prefix + "/completeTask/" + taskid,
	            type : "POST",
	            data : JSON.stringify(json), //转JSON字符串
	            dataType: 'json',
	            contentType:'application/json;charset=UTF-8', //contentType很重要
	            success : function(result) {
	                $.modal.msg("办理成功");
	                const parent = window.parent;
	                // 我的待办
	                const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
	                // 我的全部待办
	                const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
	                myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
	                myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
	                $.modal.closeTab();
	            }
	        });
	        
        });
    	}
    }

    $(document).ready(function(){
        // 获取时间轴
        $.get(prefix + "/history/" + $("#taskid").val(), function(data){
            for (var a = 0; a < data.length ; a++) {
                $("#vertical-timeline").append("<div class=\"vertical-timeline-block\"><div class=\"vertical-timeline-icon lazur-bg\">" +
                    "<i class=\"fa fa-briefcase\"></i></div>" +
                    "<div class=\"vertical-timeline-content\">" +
                    "<span class=\"vertical-date\">开始 <small>" + data[a].startTime + "</small></span><br>" +
                    "<h2><b>" + data[a].assignee + ":</b>" + data[a].taskName + "</h2>" +
                    "<p>" + (data[a].comment || "-") + "</p>" +
                    "<span class=\"vertical-date\">结束 <small>" + (data[a].endTime || "-") + "</small></span>" +
                    "</div>" +
                    "</div>");
            }
        });
    });
    
    $("input[name='bxrAt']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $(function() {
    	var data = [[${obj.item}]];
    	// 初始化数据, 可以由后台传过来
	    var options = {
	    	data: data,
            pagination: false,
	        showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            sidePagination: "client",
	        columns: [
	        {
	        	field: 'index',
	        	align: 'center',
	        	title: "序号",
                formatter: function (value, row, index) {
                	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                	var columnId = $.common.sprintf("<input type='hidden' name='item[%s].xuh' value='%s'>", index, row.id);
                	return columnIndex + $.table.serialNumber(index) + columnId;
                }
            },
	        {
	            field: 'cfrq',
	            align: 'center',
	            title: '出发日期',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:100px' required name='item[%s].cfrq' value='%s' class='form-control itemcfrq' placeholder='yyyy-MM-dd' type='hidden' autoComplete='off'>", index, value);
	            	if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        },
	        {
	            field: 'cfdd',
	            align: 'center',
	            title: '出发地点',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemcfdd' type='hidden' autoComplete='off' name='item[%s].cfdd' value='%s'>", index, value);
	            	if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        },
	        {
	            field: 'ddrq',
	            align: 'center',
	            title: '到达日期',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:100px' required name='item[%s].ddrq' value='%s' class='form-control itemddrq' placeholder='yyyy-MM-dd' type='hidden' autoComplete='off'>", index, value);
	            	if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        },
	        {
	            field: 'dddd',
	            align: 'center',
	            title: '到达地点',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemdddd' type='hidden' autoComplete='off' name='item[%s].dddd' value='%s'>", index, value);
	            	if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        },
	        {
	            field: 'rs',
	            align: 'center',
	            title: '人数',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:50px' class='form-control itemrs' type='hidden' autoComplete='off' name='item[%s].rs' value='%s'>", index, value);
	            	if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        },
	        {
	            field: 'jtfs',
	            align: 'center',
	            title: '交通方式',
// 	            formatter: function(value, row, index) {
// 	        		var data = [{ index: index, type: value }];
// 	                return $("#itemJtfs").tmpl(data).html();
//                 }
	            formatter: function(value, row, index) {
	        		return value;
                }
	        },
	        {
	            field: 'jtje',
	            align: 'center',
	            title: '交通金额',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemjtje' type='hidden' autoComplete='off' name='item[%s].jtje' value='%s'>", index, value);
	            	if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        },
	        {
	            field: 'ts',
	            align: 'center',
	            title: '天数',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:50px' class='form-control itemts' type='hidden' autoComplete='off' name='item[%s].ts' value='%s'>", index, value);
	            	if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        },
	        {
	            field: 'ccbzbz',
	            align: 'center',
	            title: '出差标准',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemccbzbz' type='hidden' autoComplete='off' name='item[%s].ccbzbz' value='%s'>", index, value);
	            	if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        },
	        {
	            field: 'ccbzje',
	            align: 'center',
	            title: '补助金额',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemccbzje' type='hidden' autoComplete='off' name='item[%s].ccbzje' value='%s'>", index, value);
	            	if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        },
	        {
	            field: 'ccbzzs',
	            align: 'center',
	            title: '住宿费用',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemccbzzs' type='hidden' autoComplete='off' name='item[%s].ccbzzs' value='%s'>", index, value);
	            	if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        },
	        {
	            field: 'qtfyjesnjt',
	            align: 'center',
	            title: '燃油交通费',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemqtfyjesnjt' type='hidden' autoComplete='off' name='item[%s].qtfyjesnjt' value='%s'>", index, value);
	            	if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        },
	        {
	            field: 'qtfyjejery',
	            align: 'center',
	            title: '其它费用',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemqtfyjejery' type='hidden' autoComplete='off' name='item[%s].qtfyjejery' value='%s'>", index, value);
	        		if(value==null){
	        			return "";
	        		}else{
	        			return html+value;
	        		}
                }
	        }]
	    };
	    $.table.init(options);
	});
    
    $.validator.addMethod("itemcfrq", function(value, element) {
        return !this.optional(element);
    }, "出发日期必填。");
    $.validator.addMethod("itemcfdd", function(value, element) {
        return !this.optional(element);
    }, "出发地点必填。");
    $.validator.addMethod("itemddrq", function(value, element) {
        return !this.optional(element);
    }, "到达日期必填。");
    $.validator.addMethod("itemdddd", function(value, element) {
        return !this.optional(element);
    }, "到达地点必填。");
    $.validator.addMethod("itemrs", function(value, element) {
        return !this.optional(element);
    }, "人数必填。");
    $.validator.addMethod("itemjtfs", function(value, element) {
        return !this.optional(element);
    }, "交通方式必填。");
    $.validator.addMethod("itemjtje", function(value, element) {
        return !this.optional(element) && (value <= 100000 && value >= 1);
    }, "交通金额长度区间1-100000。");
    $.validator.addMethod("itemts", function(value, element) {
        return !this.optional(element);
    }, "天数必填。");
    
    /**
    $.validator.addMethod("itemccbzbz", function(value, element) {
        return !this.optional(element);
    }, "标准必填。");
    $.validator.addMethod("itemccbzje", function(value, element) {
        return !this.optional(element) && (value <= 100000 && value >= 1);
    }, "金额长度区间1-100000。");
    $.validator.addMethod("itemccbzzs", function(value, element) {
        return !this.optional(element);
    }, "住宿必填。");
    
    $.validator.addMethod("itemqtfyjesnjt", function(value, element) {
        return !this.optional(element) && (value <= 100000 && value >= 1);
    }, "市内交通长度区间1-100000。");
    $.validator.addMethod("itemqtfyjejery", function(value, element) {
        return !this.optional(element) && (value <= 100000 && value >= 1);
    }, "燃油长度区间1-100000。");
    $.validator.addMethod("itemqtfyjetcf", function(value, element) {
        return !this.optional(element) && (value <= 100000 && value >= 1);
    }, "停车费长度区间1-100000。");
    **/
    
    function addRow() {
    	
    	var count = $("#" + table.options.id).bootstrapTable('getData').length;
    	
    	var row = {
            index: $.table.serialNumber(count),
            cfrq: "",
            cfdd: "",
            ddrq: "",
            dddd: "",
            rs: "",
            jtfs: "",
            jtje: "",
            ts: "",
            ccbzbz: "",
            ccbzje: "",
            ccbzzs: "",
            qtfyjesnjt: "",
            qtfyjejery: "",
            qtfyjetcf: ""
        }
    	sub.addColumn(row);
    	
    	for(var i=0;i<=count;i++){
    		$("input[name='item["+i+"].cfrq']").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });
        	$("input[name='item["+i+"].ddrq']").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });
    	}
    	
    }
</script>
</body>
</html>

<!-- 成本类型 -->
<script id="itemJtfs" type="text/x-jquery-tmpl">
<div>
<select class='form-control' name='item[${index}].jtfs' style='width:70px'>
<option value="火车" {{if type==="火车"}}selected{{/if}}>火车</option>
<option value="汽车" {{if type==="汽车"}}selected{{/if}}>汽车</option>
<option value="飞机" {{if type==="飞机"}}selected{{/if}}>飞机</option>
</select>
</div>
</script>